<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<jsp:include page="/pages/sysIndex/default.jsp"/>
<div class="main-content">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">
                <i class="fa icon-trophy"></i> 版本号管理
            </div>
            <div class="box-tools pull-right">
                <a href="#" class="btn btn-default" id="btnSearch" title="查询"><i class="fa fa-filter"></i> 查询</a>
                <sec:authorize access="hasAnyRole({'ROLE_ENTERPRISE_DICT_EDIT'})">
                    <a href="javascript:;" onclick="vLayuiUtil.openLayerWindow('wAppVersion', '<c:url
                            value="/web/admin/appVersion/getAppVersionEditPage.action"/>','新增')"
                       class="btn btn-default btnTool"
                       title="新增权限"><i class="fa fa-plus"></i> 新增</a>
                </sec:authorize>
            </div>
        </div>
        <div class="box-body">
            <form id="searchForm" action="<c:url value="/web/admin/appVersion/getAppVersionListJSON.action"/>"
                  method="post"
                  class="form-inline hide" data-page-no="1" data-page-size="20" data-order-by="">
                <div class="form-group">
                    <label class="control-label">版本号：</label>
                    <div class="control-inline">
                        <input type="text" id="searchCode" name="searchCode" value="" maxlength="64"
                               class="form-control width-120">
                    </div>
                </div>

                <div class="form-group">
                    <label class="control-label">app类型：</label>
                    <div class="control-inline" style="width: 120px">
                        <select id="deviceType" name="deviceType" class="form-control">
                            <option value="">全部</option>
                            <c:forEach items="${deviceTypeArray}" var="type">
                                <option value="${type.code}">${type.name}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>

                <div class="form-group">
                    <label class="control-label">环境：</label>
                    <div class="control-inline" style="width: 120px">
                        <select id="surroundings" name="surroundings" class="form-control">
                            <option value="">全部</option>
                            <c:forEach items="${surroundingsArray}" var="type">
                                <option value="${type.code}">${type.name}</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>

                <div class="form-group">
                    <button type="submit" class="btn btn-primary btn-sm">查询</button>
                    <button type="reset" class="btn btn-default btn-sm">重置</button>
                </div>
            </form>
            <div style="overflow-x:auto">
                <table id="dataGrid"></table>
            </div>
            <div id="dataGridPage"></div>
        </div>
    </div>
</div>
<script>
    $('#dataGrid').dataGrid({
        shrinkToFit: false,
        autoScroll: true,
        searchForm: $("#searchForm"),
        columnModel: [
            {
                header: '操作',
                name: 'actions',
                width: 150,
                align: "center",
                sortable: false,
                title: false,
                formatter: function (val, obj, row, act) {
                    var result='';
                    var editUrl = '<c:url value="/web/admin/appVersion/getAppVersionEditPage.action?id="/>' + row.id;
                   <sec:authorize access="hasAnyRole({'ROLE_ENTERPRISE_DICT_EDIT'})">
                     result = '<a href="javascript:;" class="btn btn-default btn-xs btnList" onclick="vLayuiUtil.openLayerWindow(\'wAppVersion\', \'' + editUrl + '\',\'编辑\')"><i class="fa fa-pencil">编辑</i></a>&nbsp;';
                    result += '<a href="javascript:;" class="btn btn-default btn-xs btnList" title="删除" onclick="del(\'' + row.id + '\')"><i class="fa fa-trash-o">删除</i></a>&nbsp;';
                    </sec:authorize>
                    return result;

                }
            },
            {header: '版本号', name: 'version', index: 'version', width: 200, align: "center"},
            {header: '版本编码', name: 'versionCode', index: 'versionCode', width: 200, align: "center"},
            {header: 'app类型', name: 'deviceTypeName', index: 'deviceType', width: 200, align: "center"},
            {header: '环境', name: 'surroundingsName', index: 'surroundings', width: 200, align: "center"},
            {header: '更新描述', name: 'updateSub', index: 'updateSub', width: 400, align: "center"},
            {header: 'app下载地址', name: 'appUrl', index: 'appUrl', width: 500, align: "center"}
        ],
        // 加载成功后执行事件
        ajaxSuccess: function (data) {

        }
    });

    function del(id) {
        js.confirm('你确认要删除这条数据吗？', function () {
            $.ajax({
                type: 'POST',
                url: "<c:url value="/web/admin/appVersion/logicRemoveAppVersion.action"/>",
                data: {
                    id: id
                },
                dataType: 'json',
                async: false,
                error: function (data) {
                    js.showErrorMessage(data.responseText);
                },
                success: function (data, status, xhr) {
                    js.showMessage(data.msg);
                    if (data.status == Global.NO) {
                        $('#dataGrid').dataGrid("refresh");
                    }
                }
            });
        });
    }

</script>